"""
文件上传相关的 Pydantic 模式
"""
from typing import Optional
from pydantic import BaseModel, Field


class UploadResponse(BaseModel):
    """文件上传响应模式"""
    filename: str = Field(..., description="文件名")
    original_filename: str = Field(..., description="原始文件名")
    file_path: str = Field(..., description="文件路径")
    file_url: str = Field(..., description="文件访问URL")
    file_size: int = Field(..., description="文件大小（字节）")
    content_type: str = Field(..., description="文件类型")

    class Config:
        json_schema_extra = {
            "example": {
                "filename": "20240726_123456_image.jpg",
                "original_filename": "company_logo.jpg",
                "file_path": "/uploads/images/20240726_123456_image.jpg",
                "file_url": "http://localhost:8001/uploads/images/20240726_123456_image.jpg",
                "file_size": 102400,
                "content_type": "image/jpeg"
            }
        }


class ImageUploadResponse(UploadResponse):
    """图片上传响应模式"""
    width: Optional[int] = Field(None, description="图片宽度")
    height: Optional[int] = Field(None, description="图片高度")
    thumbnail_url: Optional[str] = Field(None, description="缩略图URL")


class UploadConfig(BaseModel):
    """上传配置模式"""
    max_file_size: int = Field(default=10 * 1024 * 1024, description="最大文件大小（字节）")
    allowed_extensions: list[str] = Field(
        default=["jpg", "jpeg", "png", "gif", "webp"],
        description="允许的文件扩展名"
    )
    upload_path: str = Field(default="uploads", description="上传目录")

    class Config:
        json_schema_extra = {
            "example": {
                "max_file_size": 10485760,
                "allowed_extensions": ["jpg", "jpeg", "png", "gif", "webp"],
                "upload_path": "uploads"
            }
        }